/*******************************************************************************
* This file provides the functions for the Input Capture module.
*
* Author: Kong Wai Weng @ Cytron Technologies Sdn. Bhd.
*******************************************************************************/



#ifndef _HAL_IC_H
#define _HAL_IC_H



#include <InCap.h>
#include "variables.h"
#include "task.h"
#include "system.h"
#include "hal_oc.h"



/*******************************************************************************
* STRUCTURE, UNION AND ENUMERATION DEFINITION                                  *
*******************************************************************************/

enum MODE {
    MANUAL      = 0,
    STABILIZED  = 2,
    AUTO        = 10,
    RTL         = 11,
};	



/*******************************************************************************
* PUBLIC FUNCTION PROTOTYPES                                                   *
*******************************************************************************/

/*******************************************************************************
* PUBLIC FUNCTION: vInitIc
*
* PARAMETERS:
* ~ void
*
* RETURN:
* ~ void
*
* DESCRIPTIONS:
* Initialize the Input Capture module 1 - 8.
*
*******************************************************************************/
void vInitIc(void);



/*******************************************************************************
* PUBLIC FUNCTION: uiGetRcRx
*
* PARAMETERS:
* ~ ucChannel	- The RC Rx channel that we want to read.
*
* RETURN:
* ~ The RC Rx pulse width value in 0.2us step (Ex: 1.5ms = 7500). 
*
* DESCRIPTIONS:
* Get the RC Rx pulse width.
*
*******************************************************************************/
unsigned int uiGetRcRx(unsigned char ucChannel);



/*******************************************************************************
* PUBLIC FUNCTION: eGetControlMode
*
* PARAMETERS:
* ~ void
*
* RETURN:
* ~ The current control mode.
*
* DESCRIPTIONS:
* Get the control mode determined by the switch on the RC Tx.
*
*******************************************************************************/
enum MODE eGetControlMode(void);



/*******************************************************************************
* TASK: taskRcRxWatchdog
*
* DESCRIPTIONS:
* This task monitors the pulse from the RC Receiver. If no pulse is detected
* after the timeout period, the error flag will be set.
*
*******************************************************************************/
portTASK_FUNCTION_PROTO(taskRcRxWatchdog, pvParameters);



#endif
